﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;

namespace CodeGecko.SocialControl {
    public abstract class BaseSocialControl : ComplexProperty<string> {
        protected virtual string ControlName { get { return "BaseSocialControl"; } }
        
        protected ComplexProperty<string> GlobalSettings { get; set; }
        
        public virtual string RegisterGlobalSettings() { throw new NotImplementedException(); }
        
        protected virtual string LoaderUrl { get { throw new NotImplementedException(); } }
        
        public BaseSocialControl() : base() {
            this.PreRender += SocialControl_PreRender;
            this.GlobalSettings = new ComplexProperty<string>();
        }

        protected void SocialControl_PreRender(object sender, EventArgs e) {
            if(!Page.ClientScript.IsStartupScriptRegistered(String.Concat(this.ControlName, "GlobalSettings")))
                Page.ClientScript.RegisterStartupScript(this.GetType(), String.Concat(this.ControlName, "GlobalSettings"), this.RegisterGlobalSettings(), true);
            if(!Page.ClientScript.IsClientScriptIncludeRegistered(String.Concat(this.ControlName, "Loader")))
                Page.ClientScript.RegisterClientScriptInclude(String.Concat(this.ControlName, "Loader"), this.LoaderUrl);
        }
    }
}
